<template>
  <PCard
    class="sipi-tax-declaration-con"
    :isCardBorder="false"
    :shadow="'never'"
    :isHeadBottomBorder="true"
    :bodyStyle="{ width: '100%' }"
  >
    <div slot="header" class="std-title">
      <span>本季度开票明细</span>
      <div class="btn-g-con">
        <div class="btn-order-info" v-if="supplementaryTaxConfig.show">
          <div class="label">{{ supplementaryTaxConfig.label }}</div>
          <div class="value">{{ supplementaryTaxConfig.amount }} {{ supplementaryTaxConfig.unit }}</div>
        </div>
        <div class="btn">
          <a-button
            v-show="btnConfig.show"
            :disabled="btnConfig.disabled"
            @click="btnEvent"
            type="primary"
            block
            style="width: 150px"
          >
            {{ btnConfig.label }}</a-button
          >
        </div>
      </div>
    </div>
    <div class="data-body">
      <div class="data-list">
        <a-table :columns="columns" :data-source="data" bordered>
          <template slot="name" slot-scope="text">
            <a>{{ text }}</a>
          </template>
          <span slot="taxType" slot-scope="text">
            {{ { 1: '专票', 2: '普票' }[text] }}
          </span>
          <span slot="taxMedium" slot-scope="text">
            {{ { 1: '纸质', 2: '电子' }[text] }}
          </span>
          <span slot="amountf2y" slot-scope="text">
            {{ fen2yuan(text || '0') }}
            <!-- {{ text }} -->
          </span>
        </a-table>
      </div>

      <div class="action" v-show="descConfig.show">
        <div class="mesg">备注信息：{{ descConfig.mesg }}</div>
      </div>
      <div class="data-list group">
        <div class="group-title">本季度税务申报</div>
        <a-table
          :columns="groupData.tdaq.columns"
          :data-source="groupData.tdaq.data"
          bordered
          :scroll="{ y: 400 }"
          class="group-table"
        >
          <template slot="title" slot-scope="currentPageData"> 本季度申报总额 </template>
          <template slot="footer" slot-scope="currentPageData">
            <div class="table-row">
              <div class="table-cell">本季度收入合计</div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell">{{ bjdsrhj }}</div>
            </div>
          </template>
        </a-table>
        <a-table
          :columns="groupData.ttpq.columns"
          :data-source="groupData.ttpq.data"
          bordered
          :scroll="{ y: 400 }"
          class="group-table"
        >
          <template slot="title" slot-scope="currentPageData"> 本季度纳税总额 </template>
          <template slot="footer" slot-scope="currentPageData">
            <div class="table-row">
              <div class="table-cell">税费合计</div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell">{{ sfhj }}</div>
            </div>
          </template>
        </a-table>
        <!-- <div class="itd-con"><span>个税费差额：</span><span>{{ groupData.itd }}</span></div> -->
      </div>
    </div>
  </PCard>
</template>

<script>
import getDataForDB from '@/api/qsbBusinessManagement'
import getDataForDB1 from '@/api/MoveLayout'
import * as Utils from '@/utils/util'

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    tel: '纸质',
    phone: '普票',
    address: '11',
    address1: '44',
    address2: '44',
    address3: '44',
    address4: '44',
    address5: '44',
    address6: '44',
    address7: '44',
  },
  {
    key: '2',
    name: 'Jim Green',
    tel: '纸质',
    phone: '普票',
    age: 42,
    address: '11',
    address1: '44',
    address2: '44',
    address3: '44',
    address4: '44',
    address5: '44',
    address6: '44',
    address7: '44',
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    tel: '纸质',
    phone: '普票',
    address: '22',
    address1: '44',
    address2: '44',
    address3: '44',
    address4: '44',
    address5: '44',
    address6: '44',
    address7: '44',
  },
  {
    key: '4',
    name: 'Jim Red',
    age: 18,
    tel: '纸质',
    phone: '普票',
    address: '33',
    address1: '44',
    address2: '44',
    address3: '44',
    address4: '44',
    address5: '60',
    address6: '44',
    address7: '44',
  },
  // {}
  // {
  //   key: '5',
  //   name: 'Jake White',
  //   age: 18,
  //   tel: '纸质',
  //   phone: '普票',
  //   address: '44',
  //   address1: '10',
  //   address2: '10',
  //   address3: '10',
  //   address4: '10',
  //   address5: '10',
  //   address6: '10',
  //   address7: '-10',
  // },
  // {
  //   key: '6',
  //   name: '合计',
  //   age: 18,
  //   tel: '纸质',
  //   phone: '普票',
  //   address: '440',
  //   address1: '441',
  //   address2: '442',
  //   address3: '443',
  //   address4: '444',
  //   address5: '445',
  //   address6: '446',
  //   address7: '447',
  // },
]

let tempDataObj = {
  address1: [],
  address2: [],
  address3: [],
  address4: [],
  address5: [],
  address6: [],
  address7: [],
}

const getColumnsList = (tempDataObj, rowSize_) => {
  const rowSize = rowSize_
  const columns = [
    {
      title: '开票时间',
      dataIndex: 'taxDate',
      customRender: (text, row, index) => {
        // console.log('开票时间=====>', text, row, index);
        if (index < rowSize) {
          return text
        }
        return {
          children: '合计',
          attrs: {
            colSpan: 5,
          },
        }
      },
    },
    {
      title: '购票方',
      dataIndex: 'entName',
      customRender: (value, row, index) => {
        const obj = {
          children: value,
          attrs: {},
        }
        if (index === rowSize) {
          obj.attrs.colSpan = 0
        }
        return obj
      },
    },
    {
      title: '发票类型',
      colSpan: 2,
      dataIndex: 'taxType',
      scopedSlots: { customRender: 'taxType' },
      customRender: (value, row, index) => {
        const obj = {
          children: { 1: '专票', 2: '普票' }[value],
          attrs: {},
        }
        // if (index === 2) {
        //   // obj.attrs.rowSpan = 3;
        // }
        // These two are merged into above cell
        // if (index === 3) {
        //   obj.attrs.rowSpan = 0;
        // }
        if (index === rowSize) {
          obj.attrs.colSpan = 0
        }
        return obj
      },
    },
    {
      title: '发票类型',
      colSpan: 0,
      dataIndex: 'taxMedium',
      scopedSlots: { customRender: 'taxMedium' },
      customRender: (value, row, index) => {
        const obj = {
          children: { 1: '纸质', 2: '电子' }[value],
          attrs: {},
        }
        if (index === rowSize) {
          obj.attrs.colSpan = 0
        }
        return obj
      },
    },
    {
      title: '开票金额',
      dataIndex: 'amount',
      customRender: (value, row, index) => {
        const obj = {
          children: Utils.conversionElement(value),
          attrs: {},
        }
        if (index === rowSize) {
          obj.attrs.colSpan = 0
        }
        return obj
      },
    },
    {
      title: '预缴个税',
      dataIndex: 'personalTax',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴个税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address1'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     // console.log('#######',index,rowSize,'||',text,JSON.stringify(tempDataObj['address1']));
      //     return text;
      //   }
      //   const ll = tempDataObj['address1'].join('+')
      //   const tempVal = eval(ll)
      //   // console.log('************', index, rowSize, ll, tempVal, JSON.stringify(tempDataObj));
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },

    {
      title: '预缴增值税',
      dataIndex: 'vat',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴增值税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address2'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address2'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },
    {
      title: '预缴附加税',
      dataIndex: 'additionalTax',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴附加税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address3'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address3'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },
    {
      title: '实缴个税',
      dataIndex: 'personalTaxReal',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴附加税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address4'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address4'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },

    {
      title: '实缴增值税',
      dataIndex: 'vatReal',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴附加税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address5'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address5'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },
    {
      title: '实缴附加税',
      dataIndex: 'additionalTaxReal',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴附加税=====>', text, row, index);
      //   if (index < rowSize) {
      //     tempDataObj['address6'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address6'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },
    {
      title: '应补差额',
      dataIndex: 'differenceAmount',
      scopedSlots: { customRender: 'amountf2y' },
      // customRender: (text, row, index) => {
      //   // console.log('预缴附加税=====>', text, row, index,rowSize,tempDataObj);
      //   if (index < rowSize ) {
      //     tempDataObj['address7'].push(isNaN(Number(text)) ? 0 : Number(text))
      //     return text;
      //   }
      //   const tempVal = eval(tempDataObj['address7'].join('+'))
      //   return {
      //     children: text,
      //     attrs: {
      //       colSpan: 1,
      //     },
      //   };
      // },
    },
  ]
  console.log('getColumnsList===>', rowSize, columns)
  return columns
}
const columns_tdaq = [
  {
    title: '类别',
    align: 'center',
    dataIndex: 'classification',
  },
  {
    title: '增值税发票',
    align: 'center',
    colSpan: 2,
    dataIndex: 'ValueAddedTaxInvoice',
  },
  {
    title: '增值税发票',
    align: 'center',
    colSpan: 0,
    dataIndex: 'ValueAddedTaxInvoice1',
  },
  {
    title: '增值税普票',
    align: 'center',
    dataIndex: 'VATGeneralInvoice',
  },
  {
    title: '未开票收入',
    align: 'center',
    dataIndex: 'unbilledRevenue',
  },
]
const columns_ttpq = [
  {
    title: '类别',
    align: 'center',
    dataIndex: 'classification',
  },
  {
    title: '增值税',
    align: 'center',
    dataIndex: 'valueAddedTax',
  },
  {
    title: '附加税',
    align: 'center',
    dataIndex: 'additionalTax',
  },
  {
    title: '个人经营所得税',
    align: 'center',
    dataIndex: 'personalTaxReal',
  },
  {
    title: '实缴附加税',
    align: 'center',
    dataIndex: 'additionalTaxReal2',
  },
  {
    title: '税费差额',
    align: 'center',
    dataIndex: 'differenceAmount',
  },
]

export default {
  name: 'sipiTaxDeclaration',
  props: {
    pageInfo: { type: Object },
  },
  data() {
    const ll = getColumnsList(tempDataObj, 5)
    return {
      groupData: {
        // 本季度申报总额
        tdaq: {
          columns: columns_tdaq,
          data: [
            // { classification: '1', ValueAddedTaxInvoice: '2', ValueAddedTaxInvoice1: '3', VATGeneralInvoice: '4', UnbilledRevenue: '5' },
            // { classification: '1', ValueAddedTaxInvoice: '2', ValueAddedTaxInvoice1: '3', VATGeneralInvoice: '4', UnbilledRevenue: '5' },
            // { classification: '1', ValueAddedTaxInvoice: '2', ValueAddedTaxInvoice1: '3', VATGeneralInvoice: '4', UnbilledRevenue: '5' },
            // { classification: '1', ValueAddedTaxInvoice: '2', ValueAddedTaxInvoice1: '3', VATGeneralInvoice: '4', UnbilledRevenue: '5' },
            {
              classification: '税率',
              ValueAddedTaxInvoice: '--',
              ValueAddedTaxInvoice1: '--',
              VATGeneralInvoice: '--',
              unbilledRevenue: '1%',
            },
            {
              classification: '收入金额',
              ValueAddedTaxInvoice: '--',
              ValueAddedTaxInvoice1: '--',
              VATGeneralInvoice: '--',
              unbilledRevenue: '',
            },
          ],
        },
        // 本季度纳税总额
        ttpq: {
          columns: columns_ttpq,
          data: [
            // { classification: '税费金额', valueAddedTax: '22222', additionalTax: '33222', personalBusinessIncomeTax: '2342344' },
            {
              classification: '税费金额',
              valueAddedTax: '--',
              additionalTax: '--',
              personalTaxReal: '--',
              additionalTaxReal2: '--',
              differenceAmount: '--',
            },
          ],
        },
        // 个税费差额：
        itd: '123元',
        // 本季度收入合计  当接口有时，使用接口的
        tdaqSum:'',
        // 税费合计
        sfhj: '--',
      },
      btnConfig: {
        disabled: false,
        label: '',
        state: 0,
        show: false,
      },
      supplementaryTaxConfig: {
        show: false,
        amount: 0,
        unit: '元',
        label: '您需要补缴税费：',
      },
      descConfig: {
        show: true,
        mesg: '无则不显示',
      },
      data: [],
      columns: ll,

      apiList: {
        178: ['本季度申报总额'],
        177: ['本季度申报总额177'],
        // 178: ['查询企业信息及个税申报详情', '本季度申报总额', '客户确认未开票收入'],
        // 177: ['查询企业信息及个税申报详情177', '本季度申报总额177', '客户确认未开票收入177']
      },
      // 查账征收  178    核定征收 177
      pageType: 177,
    }
  },
  computed: {
    // 本季度收入合计
    bjdsrhj() {
      const temp = this.groupData.tdaq.data[1]
      const sum_ = this.groupData.tdaqSum;
      return sum_ || this.getTableRowCalue(temp, ['classification']).toFixed(2)
    },
    // 税费合计
    sfhj() {
      const temp = this.groupData.ttpq.data[0]
      return this.getTableRowCalue(temp, ['classification']).toFixed(2)
    },
  },
  watch: {
    data: {
      handler(val) {
        this.setColumns(val)
        console.log(tempDataObj)
      },
      deep: true,
      immediate: true,
    },
    pageInfo: {
      handler(val) {
        if (Object.prototype.toString.call(val) === '[object Object]') {
          const {
            dbData,
            pageData: { name },
          } = val
          const pageName = {
            税务申报: 177,
            个税申报: 178,
          }
          this.pageType = pageName[name]
          this.$nextTick(() => {
            // details  remarks
            if (dbData.remarks) {
              this.descConfig.show = true
              this.descConfig.mesg = dbData.remarks
            } else {
              this.descConfig.show = false
              this.descConfig.mesg = ''
            }
            this.data = this.dataSum([...(dbData.details || [])])

            this.getPageDataForAPI(dbData.flowNo)
            this.setTTPQData(dbData)
          })
        }
      },
      deep: true,
      immediate: false,
    },
  },
  mounted() {
    // setTimeout(() => {
    //   this.data = this.dataSum([...data])
    // }, 1000)
    console.log(tempDataObj)
  },
  methods: {
    getTableRowCalue(rowObj, notKey = []) {
      let sum = 0
      Object.keys(rowObj).forEach((key) => {
        if (notKey.indexOf(key) >= 0) {
          return false
        }
        try {
          const value = Number(rowObj[key])
          sum += isNaN(value) ? 0 : value
        } catch (error) {}
      })
      return sum
    },
    fen2yuan(val) {
      return Utils.conversionElement(val)
    },
    setColumns(tableData) {
      if (Object.prototype.toString.call(tableData) === '[object Array]') {
        const dataSize = tableData.length - 1
        this.columns = getColumnsList(tempDataObj, dataSize)
        this.$forceUpdate()
      }
    },
    getPaidAmount(orderNo) {
      getDataForDB('根据订单编号获取待支付金额', { orderNo }).then((res) => {
        const { success, result } = res
        if (success) {
          this.supplementaryTaxConfig.show = true
          this.supplementaryTaxConfig.amount = this.fen2yuan(result.amount)
        }
      })
    },
    dataSum(dataArr) {
      const ll = {
        key: '',
        taxDate: '',
        entName: '',
        taxType: '',
        taxMedium: '',
        amount: '',
        personalTax: 0,
        vat: 0,
        additionalTax: 0,
        personalTaxReal: 0,
        vatReal: 0,
        additionalTaxReal: 0,
        differenceAmount: 0,
      }
      const tempSumKey = [
        'personalTax',
        'vat',
        'additionalTax',
        'personalTaxReal',
        'vatReal',
        'additionalTaxReal',
        'differenceAmount',
      ]
      // dataArr.forEach(item => {
      //   tempSumKey.forEach(key => {
      //     ll[key] += isNaN(Number(item[key])) ? 0 : Number(item[key])
      //   })
      // });
      const tempdataArr = JSON.parse(JSON.stringify(dataArr))
      if (dataArr.length > 0) {
        const lastData = dataArr[dataArr.length - 1]
        tempSumKey.forEach((key) => {
          ll[key] = isNaN(Number(lastData[key])) ? 0 : Number(lastData[key])
        })
      }

      // 实缴的 - 预交的 = 差额
      // 当 差额 为大于0时  按钮【支付税费差额】  当 差额 为小于0时 按钮【确认申报内容】  当 差额 为等于0时  按钮【确认申报内容】
      this.supplementaryTaxConfig.amount = ll['differenceAmount'] =
        ll['personalTaxReal'] +
        ll['vatReal'] +
        ll['additionalTaxReal'] -
        (ll['personalTax'] + ll['vat'] + ll['additionalTax'])
      //  业务办理状态 全部 5待提交 10待审核 20审核驳回 23待发布 24待确认 25资料待完善 26待认证 30待支付 33待退款 40支付失败 50办理中 60办理完成 70已取消 80办理失败
      const statusList = {
        23: () => {
          this.btnConfig.show = true
          this.btnConfig.label = '待发布'
          // 确认之后  直接隐藏 按钮
          this.btnConfig.state = 3
        },
        24: () => {
          this.btnConfig.show = true
          this.btnConfig.label = '确认申报内容'
          // 确认之后  直接隐藏 按钮
          this.btnConfig.state = 2
        },
        30: () => {
          this.btnConfig.show = true
          this.btnConfig.label = '支付税费差额'
          // 确认之后  直接隐藏 按钮
          this.btnConfig.state = 1
          this.getPaidAmount(this.pageInfo.dbData.orderNo)
        },
        26: () => {
          // this.pageInfo.dbData.status == 30
          this.btnConfig.show = true
          this.btnConfig.label = '客户认证'
          // 确认之后  直接隐藏 按钮
          this.btnConfig.state = 4
        },
        "无":()=>{
          this.btnConfig.show = false
          this.btnConfig.label = ''
          this.btnConfig.state = -1
        }
      }
      const statusCode = this.pageInfo.dbData.status

      if(statusList[statusCode]){
        console.log('@@@@@@@@@@@',statusCode,statusList[statusCode]);
        statusList[statusCode]()
      }else{
        statusList['无']()
      }
      // if (this.pageInfo.dbData.status == 24) {
      //   this.btnConfig.show = true
      //   this.btnConfig.label = '确认申报内容'
      //   // 确认之后  直接隐藏 按钮
      //   this.btnConfig.state = 2
      //   // this.supplementaryTaxConfig.label = '您需要补缴税费：'
      // } else if (this.pageInfo.dbData.status == 30) {
      //   // this.pageInfo.dbData.status == 30
      //   this.btnConfig.show = true
      //   this.btnConfig.label = '支付税费差额'
      //   // 确认之后  直接隐藏 按钮
      //   this.btnConfig.state = 1
      //   this.getPaidAmount(this.pageInfo.dbData.orderNo)
      // } else if (this.pageInfo.dbData.status == 26) {
      //   // this.pageInfo.dbData.status == 30
      //   this.btnConfig.show = true
      //   this.btnConfig.label = '客户认证'
      //   // 确认之后  直接隐藏 按钮
      //   this.btnConfig.state = 4
      //   this.getPaidAmount(this.pageInfo.dbData.orderNo)
      // } else {
      //   this.btnConfig.show = false
      // }

      // if (ll['differenceAmount'] > 0) {
      //   this.btnConfig.label = '支付税费差额'
      //   this.btnConfig.state = 1
      //   this.supplementaryTaxConfig.label = '您需要补缴税费：'
      // }
      // if (ll['differenceAmount'] == 0) {
      //   this.btnConfig.label = '确认申报内容'
      //   // 确认之后  直接隐藏 按钮
      //   this.btnConfig.state = 2
      //   this.supplementaryTaxConfig.label = '您需要补缴税费：'
      // }
      // if (ll['differenceAmount'] < 0) {
      //   this.btnConfig.label = '确认申报内容'
      //   this.supplementaryTaxConfig.label = '需要给您退缴税费：'
      //   // 确认之后 线下退税
      //   this.btnConfig.state = 3
      // }
      // tempdataArr.splice(0,2)
      if (dataArr.length > 1) {
        return [...tempdataArr]
        // return [...tempdataArr.splice(0,dataArr.length-1), ll]
      } else {
        return [...tempdataArr]
        // return [...tempdataArr, ll]
      }
    },
    btnEvent() {
      const tempState = {
        1: () => {
          // 跳转到收银台
          // this.$message.info('需要跳转收银台')
          const key = 'sipiTaxDeclaration'
          Utils.Storage.set(key, { orderNo: [this.pageInfo.dbData.orderNo] })
          this.$router.push({
            path: '/myAccount/accountManage',
            query: {
              po: key,
            },
          })
        },
        2: () => {
          //
          this.btnConfig.show = false
          // this.$message.info('需要调用后台接口 确认申报')
          getDataForDB('税务申报客户确认', this.pageInfo.dbData).then((res) => {
            if (res.success) {
              this.btnConfig.disabled = true
              this.$message.success(res.message || '数据提交成功')
            } else {
              this.$message.warning(res.message)
            }
          })
        },
        3: () => {
          const param = {...this.pageInfo.dbData}
          param.status = 24
          console.log('管理端点击发布，转为待确认状态', param);
          getDataForDB('管理端点击发布，转为待确认状态', param).then((res) => {
            if (res.success) {
              this.btnConfig.show = false
              this.$message.success(res.message || '数据提交成功')
            } else {
              this.$message.warning(res.message)
            }
          })
        },
        4: () => {

          const { entId, id } = this.pageInfo.dbData
          // 客户确认 进行短信验证或人脸验证
          // const param = {

          //   "bizCode": 177, // 人脸认证：开票 171 ；退票 172 ； 错票重开 173 ; 税务申报 177
          //   "bizNo": id,
          //   "entId": entId, // 企业id
          //   "type": 3, //认证方式 ：1 人脸 ； 2 短信 ；3 合同签署
          // }
          const param_new = {
            id,
          }
          getDataForDB1('法人签署认证短信邀请链接发送(新)', param_new).then((res) => {
            console.log('法人签署认证短信邀请链接发送(新)=====>', res)
            if (res.success) {
              this.btnConfig.show = false
              // result 、、 result 15910653635
              this.$message.success(`认证短信已发送至号码为【${res.result}】的手机上，请到此手机上进行认证操作！`)
              // this.$router.go(0)
            } else {
              this.$message.warning(res.message || '数据请求异常')
            }
          })
        },
      }
      tempState[this.btnConfig.state] && tempState[this.btnConfig.state]()
      // this.$router.go(0)
    },

    /**
     * 本季度纳税总额
     * @param {*} dbData
     */
    setTTPQData(dbData) {
      const apiList = {
        // 查询企业信息及个税申报详情
        178: (dataList) => {
          const { details, totalTaxes, totalRevenue, vatReal, additionalTaxReal, personalTaxReal, unbilledRevenue } =
            dataList || {}
          // this.formGroup[0].tableData.dataSource = addArr(details || [])
          // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
          // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalBusinessIncomeTax: '--' }
          // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalTaxReal: '--',additionalTaxReal2:'--',differenceAmount:'--' }
          this.groupData.ttpq.data = [
            {
              classification: '税费金额',
              valueAddedTax: this.fen2yuan(vatReal) || '--',
              additionalTax: this.fen2yuan(additionalTaxReal) || '--',
              personalTaxReal: this.fen2yuan(personalTaxReal) || '--',
              additionalTaxReal2: this.fen2yuan(additionalTaxReal2) || '--',
              differenceAmount: this.fen2yuan(differenceAmount) || '--',
            },
          ]
          // 本季度收入合计  totalRevenue
          this.groupData.bjdsrhj = this.fen2yuan(totalRevenue) || '--'
          this.groupData.sfhj = this.fen2yuan(totalTaxes) || '--'
          this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue) || '--'
        },
        // 查询企业信息及个税申报详情177
        177: (dataList) => {
          const {
            details,
            totalTaxes,
            totalRevenue,
            vatReal,
            additionalTaxReal,
            personalTaxReal,
            unbilledRevenue,
            additionalTaxReal2,
            differenceAmount,
          } = dataList || {}
          // this.formGroup[0].tableData.dataSource = addArr(details || [])
          // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
          // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalBusinessIncomeTax: '--' }
          // console.log('##########',vatReal,additionalTaxReal,personalTaxReal,additionalTaxReal2,differenceAmount,this.fen2yuan(personalTaxReal));
          this.groupData.ttpq.data = [
            {
              classification: '税费金额',
              valueAddedTax: this.fen2yuan(vatReal) || '--',
              additionalTax: this.fen2yuan(additionalTaxReal) || '--',
              personalTaxReal: this.fen2yuan(personalTaxReal) || '--',
              additionalTaxReal2: this.fen2yuan(additionalTaxReal2) || '--',
              differenceAmount: this.fen2yuan(differenceAmount) || '--',
            },
          ]
          // 本季度收入合计  totalRevenue
          this.groupData.bjdsrhj = this.fen2yuan(totalRevenue) || '--'
          this.groupData.sfhj = this.fen2yuan(totalTaxes) || '--'
          this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue) || '--'
        },
      }
      return apiList[this.pageType](dbData)
    },

    /**
     * 用于请求接口
     * @param {*} key
     * @param {*} param
     * @param {*} backFun 数据处理的回调方法
     */
    async pageGetDataForDB(key, param, backFun) {
      // console.log('用于请求接口====>', key, param, backFun);
      const res = await getDataForDB1(key, param)
      const { success, message, result } = res
      if (success) {
        // this.dbDataList[this.pageType][key] = result
        backFun(result)
      } else {
        // console.warning(key, param);
        this.$message.warning(message || `接口请求失败:${key}`)
      }
    },
    /**
     * 获取接口对应的参数
     * @param {*} urlName
     */
    getParam(urlName, flowNo) {
      const smsbizNo = flowNo // this.pageInfo.dbData.flowNo
      const apiList = {
        178: {
          本季度申报总额: () => {
            return { id: smsbizNo }
          },
        },
        177: {
          本季度申报总额177: () => {
            return { id: smsbizNo }
          },
        },
      }
      return apiList[this.pageType][urlName]()
    },
    /**
     * 获取接口返回结果对应的处理方法
     * @param {*} urlName
     */
    getbackFun(urlName) {
      const apiList = {
        178: {
          本季度申报总额: (dataList) => {
            const tempData = [
              // { name: '税率', VATInvoice: '--%', VATInvoice1: '--%', VATGeneralInvoice: '1%', unbilledRevenue: '1%' },
              // { name: '收入金额', VATInvoice: '--', VATInvoice1: '--', VATGeneralInvoice: '654', unbilledRevenue: '' },
              // { classification: '税率', ValueAddedTaxInvoice: '--%', ValueAddedTaxInvoice1: '--%', VATGeneralInvoice: '--%', unbilledRevenue: '1%' },
              // { classification: '收入金额', ValueAddedTaxInvoice: '--', ValueAddedTaxInvoice1: '--', VATGeneralInvoice: '--', unbilledRevenue: '' },
              ...this.groupData.tdaq.data,
            ]
            const { details, amount, universalTicketAmount, universalTicketRate } = dataList || {}
            // this.bjdsrhj['selfVal'] = this.fen2yuan(amount) || '--'
            tempData[0].VATGeneralInvoice = universalTicketRate && (Number(universalTicketRate) * 100) +'%' || '--'
            tempData[1].VATGeneralInvoice = this.fen2yuan(universalTicketAmount) || '--'
            details &&
              details.forEach((item, index) => {
                const { specialTicketRate, specialTicketAmount } = item
                const keyList = { 0: 'ValueAddedTaxInvoice', 1: 'ValueAddedTaxInvoice1' }
                if (keyList[index]) {
                  tempData[0][keyList[index]] = specialTicketRate && (Number(specialTicketRate) * 100) +"%" || '--'
                  tempData[1][keyList[index]] = this.fen2yuan(specialTicketAmount) || '--'
                }
              })

            this.groupData.tdaq.data = tempData
            this.groupData.tdaqSum = this.fen2yuan(amount).toFixed(2) || ''
          },
        },
        177: {
          本季度申报总额177: (dataList) => {
            const tempData = [
              // { name: '税率', VATInvoice: '--%', VATInvoice1: '--%', VATGeneralInvoice: '1%', unbilledRevenue: '1%' },
              // { name: '收入金额', VATInvoice: '--', VATInvoice1: '--', VATGeneralInvoice: '654', unbilledRevenue: '' },
              // { classification: '税率', ValueAddedTaxInvoice: '--%', ValueAddedTaxInvoice1: '--%', VATGeneralInvoice: '--%', unbilledRevenue: '1%' },
              // { classification: '收入金额', ValueAddedTaxInvoice: '--', ValueAddedTaxInvoice1: '--', VATGeneralInvoice: '--', unbilledRevenue: '' },
              ...this.groupData.tdaq.data,
            ]
            const { details, amount, universalTicketAmount, universalTicketRate } = dataList || {}
            // this.bjdsrhj['selfVal'] = this.fen2yuan(amount) || '--'
            tempData[0].VATGeneralInvoice = universalTicketRate && (Number(universalTicketRate) * 100) +'%' || '--'
            tempData[1].VATGeneralInvoice = this.fen2yuan(universalTicketAmount) || '--'
            details &&
              details.forEach((item, index) => {
                const { specialTicketRate, specialTicketAmount } = item
                const keyList = { 0: 'ValueAddedTaxInvoice', 1: 'ValueAddedTaxInvoice1' }
                if (keyList[index]) {
                  tempData[0][keyList[index]] = specialTicketRate && (Number(specialTicketRate) * 100) +"%" || '--'
                  tempData[1][keyList[index]] = this.fen2yuan(specialTicketAmount) || '--'
                }
              })

            this.groupData.tdaq.data = tempData
            this.groupData.tdaqSum = this.fen2yuan(amount).toFixed(2) || ''
          },
        },
      }
      return apiList[this.pageType][urlName]
    },
    /**
     * 设置本季度申报总额
     */
    getPageDataForAPI(flowNo) {
      if (!flowNo) {
        return false
      }
      // console.log('设置本季度申报总额 getPageDataForAPI====>', flowNo);
      const getApiList = this.apiList[this.pageType]
      getApiList.forEach((apiName, index) => {
        const param = this.getParam(apiName, flowNo)
        const backFun = this.getbackFun(apiName)
        this.pageGetDataForDB(apiName, param, backFun)
      })
    },
  },
}
</script>

<style lang="less">
.sipi-tax-declaration-con {
  .std-title {
    font-size: 20px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .btn-g-con {
      display: flex;
      justify-content: flex-end;
      align-items: center;

      .btn-order-info {
        font-size: 16px;
        margin: 0 10px;
        display: flex;
        justify-content: flex-end;
        align-items: center;

        .label {
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #666666;
        }

        .value {
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 600;
          color: #ff797f; // #333333;
        }
      }
    }
  }

  .data-body {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;

    .data-list {
      width: 100%;

      &.group {
        .group-title {
          font-size: 20px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          color: #333333;
          border-bottom: 1px solid rgb(235, 238, 245);
          padding: 10px 0;
          margin: 10px 0;
        }

        .group-table {
          .ant-pagination {
            display: none;
          }

          margin: 20px 0;

          .ant-table-title {
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: 600;
          }
          // 合计
          .ant-table-content {
            .ant-table-scroll {
              .ant-table-footer {
                padding: 16px 0px;
                .table-row {
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  .table-cell {
                    flex: 1;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                  }
                }
              }
            }
          }
        }

        .itd-con {
          margin: 10px 0;
        }
      }
    }

    .action {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .mesg {
        height: 100%;
        flex: 4;
        display: flex;
        justify-content: flex-start;
        align-items: center;
      }

      .brn-group {
        flex: 3;
        height: 100%;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        flex-direction: column;

        .btn-order-info {
          width: 100%;
          display: flex;
          justify-content: flex-end;
          align-items: center;
        }

        .btn {
          width: 100%;
          display: flex;
          justify-content: flex-end;
          align-items: center;
          padding: 10px 0;
        }
      }
    }
  }
}
</style>
